package com.stylefeng.guns.modular.system.controller;

import com.github.pagehelper.PageInfo;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.small.dto.ArtificerMeansDTO;
import com.stylefeng.guns.modular.small.util.ResponseResultDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ArtificerMeans;
import com.stylefeng.guns.modular.system.service.IArtificerMeansService;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * 技师列表控制器
 *
 * @author fengshuonan
 * @Date 2019-09-01 20:41:08
 */
@Controller
@RequestMapping("/artificerMeans")
public class ArtificerMeansController extends BaseController {

    private String PREFIX = "/system/artificerMeans/";

    @Autowired
    private IArtificerMeansService artificerMeansService;

    /**
     * 跳转到技师列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "artificerMeans.html";
    }

    /**
     * 跳转到添加技师列表
     */
    @RequestMapping("/artificerMeans_add")
    public String artificerMeansAdd() {
        return PREFIX + "artificerMeans_add.html";
    }

    /**
     * 跳转到修改技师列表
     */
    @RequestMapping("/artificerMeans_update/{artificerMeansId}")
    public String artificerMeansUpdate(@PathVariable Integer artificerMeansId, Model model) {
        ArtificerMeans artificerMeans = artificerMeansService.selectById(artificerMeansId);
        model.addAttribute("item",artificerMeans);
        LogObjectHolder.me().set(artificerMeans);
        return PREFIX + "artificerMeans_edit.html";
    }

    /**
     * 获取技师列表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return artificerMeansService.selectList(null);
    }

    /**
     * 新增技师列表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ArtificerMeans artificerMeans) {
        artificerMeansService.insert(artificerMeans);
        return SUCCESS_TIP;
    }

    /**
     * 删除技师列表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer artificerMeansId) {
        artificerMeansService.deleteById(artificerMeansId);
        return SUCCESS_TIP;
    }

    /**
     * @api {get} /artificerMeans/update  修改技师列表
     * @apiName  updateArtificerMeans
     * @apiGroup ArtificerMeans
     *
     * @apiParam {Number} id 技师id.
     * @apiParam {Number} enabled 是否启用   1为在线.
     * @apiParam {Object} [ArtificerMeans] 技师基本信息编辑,对应该对象里面的字段.
     *
     * @apiSuccessExample {json} Success-Response:
     *      HTTP/1.1 200 OK
     *    {
     * 		"message":"操作成功",
     * 	    "code":"200"
     *    }
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ArtificerMeans artificerMeans) {
        ResponseResultDTO  responseResultDTO=new ResponseResultDTO();
        artificerMeansService.updateById(artificerMeans);
        responseResultDTO.setData(artificerMeansService.selectById(artificerMeans.getId()));
        return responseResultDTO;
    }

    /**
     * 技师列表详情
     */
    @RequestMapping(value = "/detail/{artificerMeansId}")
    @ResponseBody
    public Object detail(@PathVariable("artificerMeansId") Integer artificerMeansId) {
        return artificerMeansService.selectById(artificerMeansId);
    }
    /**
     * @api {get} /artificerMeans/searchList  获取技师列表列表
     * @apiName  searchArtificerMeans
     * @apiGroup ArtificerMeans
     *
     * @apiParam {String} viewProfessionalTitle  技师技能分类
     * @apiParam {Boolean} distance  是否距离排序 默认false
     * @apiParam {Boolean} evaluation   是否评分排序  默认false
     * @apiParam {String} consumerLongitude  客户经度
     * @apiParam {String} consumerLatitude  客户维度
     * @apiParam {Number} pageCount   每页多少条数
     * @apiParam {Number} currentCount  当前第几页
     *
     * @apiSuccessExample {json} Success-Response:
     *      HTTP/1.1 200 OK
     *    {
     * 		"message":"操作成功",
     * 	    "code":"200"
     *    }
     */
    @RequestMapping(value = "/searchList")
    @ResponseBody
    public PageInfo<ArtificerMeans> searchList(String viewProfessionalTitle, Boolean  distance, Boolean  evaluation,
                                               String  consumerLongitude, String consumerLatitude,
                                               @RequestParam(defaultValue = "10",value = "pageCount")Integer pageCount,
                                               @RequestParam(defaultValue = "1",value = "currentCount")Integer  currentCount) {
        return artificerMeansService.searchList(viewProfessionalTitle,distance,evaluation,consumerLongitude,consumerLatitude,pageCount,currentCount);
    }


    /**
     * 获取技师详情
     * @auther litong
     * @date 20190907
     */
    @RequestMapping(value = "/searchDeatil")
    @ResponseBody
    public ArtificerMeansDTO searchDeatil(ArtificerMeansDTO artificerMeansDTO) {
        return artificerMeansService.searchDeatil(artificerMeansDTO);
    }

    /**
     * @api {POST} /artificerMeans/orderList  地图周边查询
     * @apiName orderListArtificerMeans
     * @apiGroup ArtificerMeans
     *
     * @apiParam {String} viewProfessionalTitle  技师技能分类.
     * @apiParam {Boolean} evaluation   是否评分排序  默认false.
     * @apiParam {Number} consumerLongitude  客户经度double.
     * @apiParam {Number} consumerLatitude  客户维度double.
     * @apiParam {String} sex  1男 0女.
     * @apiParam {Number} enabled    是否在线.
     * @apiParam {Number} distance   查询多少公里范围内的技师,默认10公里.
     * @apiParam {Boolean} distanceSort   排序方式.
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     * "data": "75a71642bd246f994a243dc92770e580",
     * "msg": "SUCCESS",
     * "status": "0000",
     * "userType": ""
     * }
     */
    @RequestMapping(value = "/orderList")
    @ResponseBody
    public ResponseResultDTO orderList(String sex, Boolean isOnline, String viewProfessionalTitle,Double  consumerLongitude,Double consumerLatitude
        ,@RequestParam(defaultValue = "10",value = "distance")Integer distance,Boolean distanceSort, Boolean  evaluation) {
        return artificerMeansService.orderList(viewProfessionalTitle,sex,isOnline,consumerLongitude,consumerLatitude,distance,distanceSort,evaluation);
    }

    /**
     * 创建订单页面
     * @param artId
     * @return
     */
    @RequestMapping(value = "/createOrderPage")
    public String createOrderPage(Integer  artId, Model model,String distincts) {
        model.addAttribute("distincts",distincts);
        return artificerMeansService.createOrderPage(artId,model);
    }
    /**
     * 预约详情页面
     * @return
     */
    @RequestMapping(value = "/toDetailedInfoPage/{id}")
    public String toDetailedInfoPage(@PathVariable Integer id,Model  model,String businessId) {
        model.addAttribute("artId",id);
        model.addAttribute("businessId",businessId);
        return "wx/wechat/detailedInfoPage.html";
    }

    /**
     * 跳转评论页面
     * @return
     */
    @RequestMapping(value = "/toCommentPage/{id}")
    public String toCommentPage(@PathVariable Integer id,Model  model) {
        artificerMeansService.findAllComment(id,model);
        return "wx/wechat/commentPage.html";
    }

    /**
     *  查询所有的评论
     * @return
     */
    @RequestMapping(value = "/findAllComment/{artificerId}")
    @ResponseBody
    public ResponseResultDTO findAllComment(@PathVariable Integer artificerId) {
        return  artificerMeansService.searchAllComment(artificerId);
    }

}
